/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package Common;

import java.io.Serializable;
import java.util.Date;
import java.util.Objects;

/**
 *
 * @author ryuk
 */
public class EmailStatusDetail implements Serializable  {
    public Long messageUniqueID;
    public EmailStatusType emailStatusType;

    public EmailStatusDetail() {
    }

    public EmailStatusDetail(Long messageUniqueID) {
        this.messageUniqueID = messageUniqueID;
    }

    public EmailStatusDetail(Long messageUniqueID, EmailStatusType emailStatusType) {
        this.messageUniqueID = messageUniqueID;
        this.emailStatusType = emailStatusType;
    }
    
    public EmailStatusDetail(EmailStatusType emailStatusType) {
        this.emailStatusType = emailStatusType;
        this.messageUniqueID = new Date().getTime();
    }
    
    public boolean isNewMessage() {
        return emailStatusType.equals(EmailStatusType.NEW);
    }
    
    public boolean isSentMessage() {
        return emailStatusType.equals(EmailStatusType.SENT);
    }
    public boolean isReceivedMessage() {
        return emailStatusType.equals(EmailStatusType.RECEIVED);
    }
    public boolean isReadMessage() {
        return emailStatusType.equals(EmailStatusType.READ);
    }
    
    public boolean isDeletedMessage() {
        return emailStatusType.equals(EmailStatusType.DELETED);
    }
    
    public String getMessageStatusAsString() {
        String result = "\n"  +
                        "------------------------------------------------" +
                        "\n"  + 
                        "Estado: ";
        switch(emailStatusType) {
            case NEW : result += "Nuevo";
                break;
            case SENT : result += "Enviado";
                break;
            case RECEIVED : result += "Recibido";
                break;
            case READ : result += "Leido";
                break;
            case DELETED : result += "Borrado";
                break;
            default : break;
        }
        result += "\n"  + 
                  "------------------------------------------------" +
                  "\n";
        return result;
    }

    @Override
    public int hashCode() {
        int hash = 7;
        hash = 53 * hash + Objects.hashCode(this.messageUniqueID);
        return hash;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final EmailStatusDetail other = (EmailStatusDetail) obj;
        return messageUniqueID.longValue() == other.messageUniqueID.longValue();
    }

    public void updateEmailStatus(EmailStatusType emailStatusType1) {
        this.emailStatusType = emailStatusType1;
    }
    public EmailStatusType retrieveEmailCurrentStatus() {
        return emailStatusType;
    }

    public Long getMessageUniqueID() {
        return messageUniqueID;
    }

    public void setMessageUniqueID(Long messageUniqueID) {
        this.messageUniqueID = messageUniqueID;
    }

    public EmailStatusType getEmailStatusType() {
        return emailStatusType;
    }

    public void setEmailStatusType(EmailStatusType emailStatusType) {
        this.emailStatusType = emailStatusType;
    }

    @Override
    public String toString() {
        return "EmailStatusDetail{" + "messageUniqueID=" + messageUniqueID + ", emailStatusType=" + emailStatusType + '}';
    }
    
}
